package com.xc.erp.modules.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xc.erp.common.utils.GetPinyin;
import com.xc.erp.modules.erp.mapper.JshSequenceMapper;
import com.xc.erp.modules.erp.domain.pojo.JshSequence;
import com.xc.erp.modules.erp.service.JshSequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.ws.Action;

/**
 * @author Administrator
 * @description 针对表【jsh_sequence(单据编号表)】的数据库操作Service实现
 * @createDate 2022-12-15 10:19:47
 */
@Service
public class JshSequenceServiceImpl extends ServiceImpl<JshSequenceMapper, JshSequence>
        implements JshSequenceService {

    @Override
    public boolean updateBuildOnlyNumber() {
        return update(new UpdateWrapper<JshSequence>().eq("seq_name", "depot_number_seq").setSql("current_val=current_val+1"));
    }

    @Autowired
    JshSequenceMapper jshSequenceMapper;
    @Transactional
    @Override
    public String getBuildOnlyNumber(String type,String subType) {
        String headPinYin="";
        if(subType.length()!=4){
            headPinYin=GetPinyin.getPinYinHeaderChar(subType+type);
        }else{
            headPinYin=GetPinyin.getPinYinHeaderChar(subType);
        }
            QueryWrapper<JshSequence> queryWrapper = new QueryWrapper<JshSequence>().eq("seq_name", "depot_number_seq");
            JshSequence sequence = jshSequenceMapper.selectOne(queryWrapper);
            String defaultNumber=headPinYin;
            for (int i = 0; i < 11-sequence.getCurrentVal().toString().length(); i++) {
                defaultNumber+="0";
            }
            return defaultNumber+(sequence.getCurrentVal()+1);
    }
}




